home *** CD-ROM | disk | FTP | other *** search
- /*
- .key file/a
- bin/cc <file>.c -a +c +l -l80 +fi -iwork:aztec/include +iwork:aztec/preinclude/include.pre +l -o ram:<file>.asm
- bin/as ram:<file>.asm -c -o ram:<file>.o
- bin/ln ram:<file>.o lib/mal32.lib lib/cl32.lib -o <file>
- */
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <graphics/gfx.h>
- #include <graphics/text.h>
- #include <time.h>
- #include <math.h>
-
- #define EOS '\0'
-
- extern double atof();
-
- double ABS(x)
- double x;
- {
- if(x<0.0) x=x*-1;
- return x;
- }
-
- double FRAC(x)
- double x;
- {
- x=x-(long)(x);
- if(x<0.0) x++;
- return(x);
- }
-
- reverse(s)
- register char *s;
- {
- register int c,i,j;
-
- for(i=0,j=strlen(s)-1; i<j ;i++,j--){
- c=s[i];
- s[i]=s[j];
- s[j]=c;
- }
- }
-
- ltoa(n,s)
- register char s[];
- register long n;
- {
- register int i=0;
- register int vorzeich=0;
- if(n<0){
- vorzeich=1;
- n=-n;
- }
- do{
- s[i++]=n%10+'0';
- }while((n/=10)>0);
- if(i<2) s[i++]='0';
- if(vorzeich)
- s[i++]='-';
- s[i]=EOS;
- reverse(s);
- }
-
-
- /****************************************************/
- /* MJD() Modifiziertes Julianisches Datum */
- /* ist genau von 1 v.Chr. bis in die Zukunft */
- /****************************************************/
- double MJD(day,month,year,hour)
- int day,month,year;
- double hour;
- {
- double a,mjd;
- int b;
-
- a=10000.0*year+100.0*month+day;
- if(month<=2){
- month=month+12;
- year=year-1;
- }
- if(a<15821004.1) b=-2+(int)((year+4716)/4)-1179;
- else b=(int)(year/400)-(int)(year/100)+(int)(year/4);
- a=365.0*year-679004.0;
- mjd=a+b+(int)(30.6001*(month+1))+day+hour/24.0;
- return(mjd);
- }
-
- /***********************************************************/
- /* LMST() mittlere Ortssternzeit (Local mean sideral time */
- /***********************************************************/
- double LMST(mjd,lambda)
- double mjd,lambda;
- {
- double mjd0,t,ut,gmst,lmst;
-
- mjd0=(long)(mjd);
- ut=(mjd-mjd0)*24.0;
- t=(mjd0-51544.5)/36525.0;
- gmst=6.697374558+1.0027379093*ut
- +(8640184.812866+(0.093104-6.2E-6*t)*t)*t/3600.0;
- lmst=24.0*FRAC((gmst-lambda/15.0)/24.0);
- return(lmst);
- }
-
-
- /* Deklarationen */
- struct Library *OpenLibrary();
- VOID CloseLibrary();
- struct Window *OpenWindow();
-
- /* externe Structuren */
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct IntuiMessage *msg=NULL;
-
- struct RastPort *rp;
- struct Window *win;
- ULONG class;
- USHORT code;
-
- /* Funktionen */
-
- SHORT OpenLib()
- {
- if(!(IntuitionBase=(struct IntuitionBase *)
- OpenLibrary("intuition.library",0))) return(1);
- if(!(GfxBase=(struct GfxBase *)
- OpenLibrary("graphics.library",0))) return(2);
- return(0);
- }
-
- VOID CloseLib()
- {
- if(IntuitionBase) CloseLibrary(IntuitionBase);
- if(GfxBase) CloseLibrary(GfxBase);
- }
-
- struct Window *GetWindow(left,top,width,height,idcmp,flags,title,gad)
- SHORT left,top,width,height;
- ULONG idcmp,flags;
- STRPTR title;
- struct Gadget *gad;
- {
- struct NewWindow NW;
- NW.LeftEdge =left;
- NW.TopEdge =top;
- NW.Width =width;
- NW.Height =height;
- NW.DetailPen=NW.BlockPen=-1;
- NW.IDCMPFlags =idcmp;
- NW.Flags =flags;
- NW.FirstGadget =gad;
- NW.CheckMark =NULL;
- NW.Title =title;
- NW.Screen =NULL;
- NW.BitMap =NULL;
- NW.MinWidth=NW.MinHeight=10;
- NW.MaxWidth =640;
- NW.MaxHeight =256;
- NW.Type =WBENCHSCREEN;
- return(OpenWindow(&NW));
- }
-
- VOID error(fehler)
- STRPTR fehler;
- {
- puts("Library Error !");
- if(win) CloseWindow(win);
- CloseLib();
- exit(0);
- }
-
- VOID Sternzeit(lambda,l2)
- double lambda, l2;
- {
- long t,h,m,s;
- struct tm *tp;
- int day,month,year;
- double hour,mjd,mjd_ut,std,min,sec;
- char hh[8], mm[8], ss[8], lmst[32];
-
- time(&t);
- tp=localtime(&t);
- day=tp->tm_mday; month=1+tp->tm_mon; year=1900+tp->tm_year;
- h=tp->tm_hour; m=tp->tm_min; s=tp->tm_sec;
- hour=h+m/60.0+s/3600.0;
- l2=l2/24.0;
- mjd=MJD(day,month,year,hour);
- mjd_ut=mjd+l2;
- std=LMST(mjd_ut,lambda);
- h=(long)(std);
- min=FRAC(std); m=(long)(min*60.0);
- sec=FRAC(min*60.0); s=(long)(sec*60.0);
- ltoa(h,hh); ltoa(m,mm); ltoa(s,ss);
- strcpy(lmst," Local mean star time: "); strcat(lmst,hh); strcat(lmst,":");
- strcat(lmst,mm); strcat(lmst,":"); strcat(lmst,ss); strcat(lmst," ");
- SetAPen(rp,1);
- Move(rp,30,7);
- Text(rp,lmst,32);
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct tm *tp;
- long t,m;
- int ok=0;
- double lambda, l2;
-
- puts("Lmst V2.0 by Th.Hausknecht 1.3.93\n");
-
- if(argc !=3) puts("error! use: Lmst [longidute] [timezone] east-/west+ MEZ = -1 MESZ = -2\n");
- else{
- lambda=atof(argv[1]);
- l2 =atof(argv[2]);
-
- if(OpenLib()){
- error("Libraries");
- }
- if(!(win=GetWindow(0,0,341,10,CLOSEWINDOW | VANILLAKEY | INTUITICKS,
- WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | ACTIVATE, 0,0))){
- error("Window");
- }
-
- rp=win->RPort;
-
- while(ok==0)
- {
- Wait(1 << win->UserPort->mp_SigBit);
- while( msg = (struct IntuiMessage *)GetMsg(win->UserPort) )
- {
- class = msg->Class;
- code = msg->Code;
- ReplyMsg(msg);
-
- switch(class)
- {
- case CLOSEWINDOW: ok++;
- break;
-
- case INTUITICKS: Sternzeit(lambda, l2);
- break;
- }
- }
- }
- ClearMenuStrip(win);
- CloseWindow(win);
- CloseLib();
- }
- }
-